import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.ServerSocket;
import java.net.Socket;


public class FileManager implements Runnable {
	ServerSocket fileRequestSocket;
	Server s;
	public FileManager(Server s) {
		this.s = s;
	}

	public void run() {
		try {
		fileRequestSocket = new ServerSocket(32000);
		while(true) {
			Socket sendSocket = fileRequestSocket.accept();
			BufferedReader socketInput = new BufferedReader(new InputStreamReader(sendSocket.getInputStream()));
			String filename = null;
			while(filename == null){
				filename = socketInput.readLine();
				System.out.println("Request for file : " + filename);
			}
			s.sendFile(sendSocket, filename);
			socketInput.close();
		}	
		
	}
	
	catch(Exception e) {
		
	}
	}	
}
